<?php

interface IGamePlayer{
	//登录游戏
	public function login($user,$password);
	
	//杀怪,网络游戏的主要特色
	public function killBoss();
	//升级
	public function upgrade();

}

class GamePlayer implements IGamePlayer{
	private $name="";
	//通过构造函数传递名称
	public function GamePlayer($_name){
		$this->name=$_name;
	}
	//打怪,最期望的就是杀老怪
	public function killBoss(){
		echo ($this->name." is killing boss. \n");
	}
	//进游戏之前你肯定要登录吧,这是一个必要条件
	public function login($user,$password){
		echo ($user."'s user ".$this->name." login success!\n");
	}
	//升级,升级有很多方法,花钱买是一种,做任务也是一种
	public function upgrade(){
		echo ($this->name." upgrade!\n");
	}
}

class GamePlayerProxy implements IGamePlayer{
	private $gamePlayer=null;
	//通过构造函数传递要对谁进行代练
	public function GamePlayerProxy(IGamePlayer $_gamePlayer){
		$this->gamePlayer=$_gamePlayer;
	}
	//代练杀怪
	public function killBoss(){
		$this->gamePlayer->killBoss();
	}
	//代练登录
	public function login($user,$password){
		$this->gamePlayer->login($user,$password);
	}
	//代练升级
	public function upgrade(){
		$this->gamePlayer->upgrade();
	}
}


//定义一个痴迷的玩家
$player=new GamePlayer("a111");
$proxy=new GamePlayerProxy($player);
//开始打游戏,记下时间戳
echo ("Start Time: 2009-8-25 10:45\n");
$proxy->login("ZhangSan","password");
//开始杀怪
$proxy->killBoss();
//升级
$proxy->upgrade();
//记录结束游戏时间
echo ("End time: 2009-8-26 03:40\n");